<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<script type="text/javascript">
<!--
	function selectorg(){
		var dlgId = "report";
		var title="选择部门";
		var url = ctx+"/common/organization-ui!getOrgUL.action?code=ROOT&idInput=org&nameInput=orgName&form=goodspermanmonthly&dlgID=report";
		$.pdialog.open(url, dlgId, title,{width:600,height:400});
	}
	function exportGoodspermanmonthly(){
		var url = "${ctx }/crm/report/goods-per-man-monthly!export.action";
		var ym = $("#goodspermanmonthlyym").val();
		var org = $("#goodspermanmonthly input[name='org']").val();
		url+="?";
		url+="ym="+ym;
		url+="&org="+org;
		window.open(url);
		}
	function queryGoodspermanmonthly(){
		var url = "${ctx }/crm/report/goods-per-man-monthly.action";
		$("#goodspermanmonthly").attr("action",url);
		}
//-->
</script>
<form id="pagerForm" method="post" action="${ctx }/crm/report/goods-per-man-monthly.action">
	<input type="hidden" name="status" value="${param.status}">
	<input type="hidden" name="keywords" value="${param.keywords}" />
	<input type="hidden" name="pageNum"  value="${page.pageNo}" />
	<input type="hidden" name="numPerPage" id="numPerPage" value="${page.pageSize}" />
	<input type="hidden" name="orderField" value="${param.orderField}" />
</form>
<div class="page">
	<div class="pageHeader">
		<form id="goodspermanmonthly" onsubmit="return navTabSearch(this);" action="${ctx }/crm/report/goods-per-man-monthly.action" method="post">
		<div class="searchBar">
			<ul class="searchContent">
				<li>
					<label>选择月份：</label>
					<span>
					<input type="text" name="ym" size="20" id="goodspermanmonthlyym" value="${ym}" onfocus="WdatePicker({el:'goodspermanmonthlyym',dateFmt:'yyyy-MM'})"/>
					</span>
				</li>
				<li>
					<label>选择部门：</label>
					<span>
					<input type="hidden" name="org" id="org" size="20" value="${org}"/>
					<input type="text" name="orgName" id="orgName" size="20" value="" onfocus="selectorg();"/>
					<!-- 
					<a class="inputButton" href="${ctx }/common/organization-ui!getOrgUL.action?code=ROOT&idInput=org&nameInput=orgName&form=goodspermanmonthly&dlgID=report" target="dialog" rel="report">选择部门</a>
					 -->
					</span>
				</li>
			</ul>
			<div class="subBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit" onclick="queryGoodspermanmonthly()"> 检 索 </button></div></div></li>
					<li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="exportGoodspermanmonthly()"> 导 出 </button></div></div></li>
				</ul>
			</div>
		</div>
		</form>
	</div>
	<div class="pageContent">
		 <div id="goodsPerManMonthlyDiv" >
		 <br>
			请按条件查询！
		</div>
		<script language="JavaScript">					
			
			var arr = new Array();
			var cate = "";
			var data = "";
			var temp = "";
			var ym = "${ym}";
			var depart = "";
			var month = ym.substr(ym.indexOf("-")+1);
			var year = ym.replace("-"+month,"");
			ym = year+"年"+month+"月份";
			var product = 0;

			//800像素，支持 4个人，5种产品，超过图像自动变宽
			var width = 800;
			var person=4;
			var pcate= 5;
			
			<s:iterator value="list" var="obj">
			arr.push(new Array("${obj[1]}","${obj[2]}","${obj[3]}","${obj[4]}"));			
			</s:iterator>	
			if(arr.length>0){
				depart = arr[0][1];
				$("#goodspermanmonthly input[id='orgName']").val(depart);
			}
			for(var i=0;i<arr.length;i++){				
				if(temp!=arr[i][0]){							
					temp=arr[i][0];										
					cate += "<category label='"+arr[i][0]+"'></category>";
					if(product==0)product=i;
					}
				}
			if(product==0){product=arr.length;}
			//宽度计算，每款产品按20像素
			if(pcate<product){
				width += (product-pcate)*20;
				}
			//宽度计算，每人按50像素
			if(person<(arr.length/product)){
				width +=((arr.length/product)-person)*50;
				}
			
			for(var i=0;i<product;i++){
				data +=" <dataset seriesName='"+arr[i][2]+"'>"
				if(person<i){
					width+=50;
					}
				for(var j=0;j<(arr.length/product);j++){
					data+="<set value='"+arr[j*product+i][3]+"' ></set>";
					//图象宽度计算
					if(pcate<j){
						width+=20;
						}
					}
				data+="</dataset>";
				}
	
			var chart1 = new FusionCharts(MSColumn3D, "chart1Id", width, "350", "0", "1");			
			var xml = "<chart caption='"+depart+"产品销量对比' subCaption='"+ym+"' xAxisName='业务员姓名' yAxisName='销售量（个）'";
			xml+=" rotateYAxisName='1' baseFont='宋体' baseFontSize='14' palette='10'";
			xml+=" showBorder='0' exportEnabled='1' exportHandler='"+explorer+"' exportAtClient='0' exportAction='download'";
			xml+=" exportFileName='SoGoodSoft'";
			xml+=" >"
			xml+="<categories>";
			xml+=cate;
			xml+="</categories>"
			xml+= data;
			xml+="</chart>";

			if(arr.length>0){
			chart1.setDataXML(xml);
			chart1.render("goodsPerManMonthlyDiv");
			}

		</script>

	</div>
</div>